package isanfeng.tuxiaoer.freemarker;

import isanfeng.tuxiaoer.freemarker.custom.SortMethod;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
public class IndexController {
    @RequestMapping("/index")
    public ModelAndView index() {
        ModelAndView view = new ModelAndView("/index");
        view.addObject("userList", initUsers());
        view.addObject("sort_int", new SortMethod());
        return view;
    }
    private List<User> initUsers() {
        List<User> users = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            User user = new User();
            user.setName("zhangsan" + i);
            user.setBirthday(new Date());
            users.add(user);
        }
        return users;
    }
}
